local hx__yicheng = fk.CreateSkill {
  name = "hx__yicheng",
  tags = { Skill.Compulsory },

}

hx__yicheng:addEffect(fk.TargetSpecifying, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local to = data.to
    local card1 = to:getCardIds{Player.Hand}
    local card2 = to:getCardIds{Player.Equip}
    local card3 = to:getCardIds{Player.Judge}
    local cards = {}
    local cardarea = {}
    if #card1 > 0 then table.insert(cardarea, "hx__yicheng_card-hand") end
    if #card2 > 0 then table.insert(cardarea, "hx__yicheng_card-equip") end
    if #card3 > 0 then table.insert(cardarea, "hx__yicheng_card-judge") end
    return data.from == player and player:hasSkill(hx__yicheng.name) and #cardarea > 0
      and data.card.trueName == "slash" and to:getMark("@@hx__yicheng-round") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local card1 = to:getCardIds{Player.Hand}
    local card2 = to:getCardIds{Player.Equip}
    local card3 = to:getCardIds{Player.Judge}
    local cards = {}
    local cardarea = {}
    if #card1 > 0 then table.insert(cardarea, "hx__yicheng_card-hand") end
    if #card2 > 0 then table.insert(cardarea, "hx__yicheng_card-equip") end
    if #card3 > 0 then table.insert(cardarea, "hx__yicheng_card-judge") end
    local choice2 = room:askToChoice(to, {
      choices = cardarea,
      skill_name = hx__yicheng.name,
      prompt = "请选择你的一个有牌的区域",
      all_choices = {"hx__yicheng_card-hand", "hx__yicheng_card-equip", "hx__yicheng_card-judge"}
    })
    if choice2 == "hx__yicheng_card-hand" then
      cards = card1
    elseif choice2 == "hx__yicheng_card-equip" then
      cards = card2
    else
      cards = card3
    end
    local choices = {"#hx__yicheng1:"..player.id,"#hx__yicheng2"}
    local choice = room:askToChoice(to, {
      choices = choices,
      skill_name = hx__yicheng.name,
      prompt = "请选择一项",
    })
    room:addPlayerMark(to, "@@hx__yicheng-round")
    if choice ~= "#hx__yicheng2" then
      room:obtainCard(player, cards, false, fk.ReasonGive, to)
      room:addPlayerMark(to, "@hx__yicheng_draw", #cards)
    else
      room:throwCard(cards,hx__yicheng.name, to, to)
      room:loseHp(to, 2, hx__yicheng.name)
      data.use.nullifiedTargets = table.simpleClone(player.room.players)
    end
  end,
})


hx__yicheng:addEffect(fk.TurnEnd, {
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(hx__yicheng.name) then return end
    local tos = table.filter(player.room:getAlivePlayers(),
      function(p) return p:getMark("@hx__yicheng_draw") > 0 end)
    return #tos > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.filter(room:getAlivePlayers(),
      function(p) return p:getMark("@hx__yicheng_draw") > 0 end)
    if #tos > 0 then
      for _, p in ipairs(tos) do
        room:drawCards(p, p:getMark("@hx__yicheng_draw"), hx__yicheng.name)
        room:setPlayerMark(p, "@hx__yicheng_draw", 0)
      end
    end
  end,
})

return hx__yicheng
